function get_host_arch(){
  local IS_Linux=$(uname -a | grep "Linux")
  local IS_X86_64=$(uname -a | grep "X86_64")
  if [ "$IS_Linux" ]; then
    HOST_ARCH=linux
  elif [ "$IS_X86_64" ]; then
    HOST_ARCH=mac-x64
  else
    HOST_ARCH=mac-arm64
  fi
}

function install_on_mac(){
  cd ~/Library/LaunchAgents
  launchctl unload com.daily.plist
  if [ "$INSTALL_CONFIG" == "-n" ];then
    echo "uninstall launchctl daily work succeed."
    exit 0
  fi
  cp ${SCRIPT_DIR}/arch/${HOST_ARCH}/com.daily.plist ./
  launchctl load -w com.daily.plist
  echo "install launchctl daily work succeed."
}

function install_on_linux(){
  crontab -r
  if [ "$INSTALL_CONFIG" == "-n" ];then
    echo "uninstall launchctl daily work succeed."
    exit 0
  fi
  crontab ${SCRIPT_DIR}/arch/${HOST_ARCH}/crontab_config.txt
  echo "install crontab daily work succeed."
}

INSTALL_CONFIG=$1
SCRIPT_DIR=$(cd $(dirname $0);pwd)
  get_host_arch
if [ "$HOST_ARCH" == "mac-arm64" ];then
  install_on_mac
elif [ "$HOST_ARCH" == "mac-x64" ];then
  install_on_mac
elif [ "$HOST_ARCH" == "linux" ];then
  install_on_linux
fi